//
//  ReturnCardTableViewCell.m
//  GLGW_Shoping
//
//  Created by whx on 2018/12/3.
//  Copyright © 2018年 yang. All rights reserved.
//

#import "ReturnCardTableViewCell.h"

@implementation ReturnCardTableViewCell
{
    GLGWLabel *detailLab;
    GLGWLabel *arLabel;
    GLGWButton *likeBtn;
    CGFloat moveNum;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        GLGWImageView *imagV = [[GLGWImageView alloc] initInSuperView:self.contentView];
        [imagV mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(@(kWidthProportion_In_iPhoneTriploid(15)));
            make.top.equalTo(@(kHeightProportion_In_iPhoneTriploid(18)));
            make.width.height.equalTo(@(kWidthProportion_In_iPhoneTriploid(44)));
        }];
//        imagV.image = [UIImage imageNamed:@"home_six"];
        imagV.backgroundColor = kRandomColor;
        imagV.layer.masksToBounds = YES;
        imagV.layer.cornerRadius = 22;

        GLGWLabel *label = [[GLGWLabel alloc] initWithFont:SYSTEMFONT(14) theColor:kColor_Rule_Black inSuperView:self.contentView];
        [label mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(@(kHeightProportion_In_iPhoneTriploid(20)));
            make.left.equalTo(imagV.mas_right).offset(kWidthProportion_In_iPhoneTriploid(10));
            make.width.equalTo(@(kWidthProportion_In_iPhoneTriploid(200)));
            make.height.equalTo(@(kHeightProportion_In_iPhoneTriploid(20)));
        }];
        label.text = @"陈也";

        GLGWLabel *label2 = [[GLGWLabel alloc] initWithFont:SYSTEMFONT(12) theColor:[UIColor colorWithHexString:@"#999999"] inSuperView:self.contentView];
        [label2 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(label.mas_left);
            make.top.equalTo(label.mas_bottom).offset(kHeightProportion_In_iPhoneTriploid(4));
            make.width.equalTo(label.mas_width);
            make.height.equalTo(@(kHeightProportion_In_iPhoneTriploid(17)));
        }];
        label2.text = @"2018-09-25 12:00";
        //
        GLGWLabel *label3 = [[GLGWLabel alloc] initWithFont:SYSTEMFONT(14) theColor:kColor_Rule_Black inSuperView:self.contentView];
        [label3 mas_updateConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(imagV.mas_left);
            make.top.equalTo(imagV.mas_bottom).offset(kHeightProportion_In_iPhoneTriploid(15));
            make.right.equalTo(@(-kWidthProportion_In_iPhoneTriploid(15)));
            make.bottom.equalTo(@(-kHeightProportion_In_iPhoneTriploid(73)));
        }];
//        label3.text = @"混沌创业营新一期开始招生，想上得可以来找我推荐在这里交来找我推荐在这里交来找我推荐到很多良师益友，是幸福也是一辈子得财富。";
        label3.numberOfLines = 0;
        detailLab = label3;
        //
        GLGWButton *but = [[GLGWButton alloc] initWithTitle:@"30" titleLableFont:SYSTEMFONT(14) titleLableColor:[UIColor colorWithHexString:@"#666666"] inSuperView:self.contentView];
        [but mas_updateConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(@(-kWidthProportion_In_iPhoneTriploid(15)));
            make.centerY.equalTo(label.mas_centerY);
            make.height.equalTo(@(kHeightProportion_In_iPhoneTriploid(40)));
            make.width.equalTo(@(60));
//            make.left.equalTo(self.contentView.mas_left).offset(kWidthProportion_In_iPhoneTriploid(300));
        }];
        [but setImage:[UIImage imageNamed:@"goods_share"] forState:UIControlStateNormal];
        but.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
        [but setImagePositionWithType:SSImagePositionTypeLeft spacing:kWidthProportion_In_iPhoneTriploid(5)];
        likeBtn = but;
        
        GLGWLabel *label4 = [[GLGWLabel alloc] initWithFont:SYSTEMFONT(14) theColor:kColor_Rule_Black inSuperView:self.contentView];
        [label4 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(imagV.mas_left);
            make.right.equalTo(@(-kWidthProportion_In_iPhoneTriploid(15)));
            make.height.equalTo(@(kHeightProportion_In_iPhoneTriploid(40)));
            make.bottom.equalTo(self.contentView.mas_bottom).offset(-kHeightProportion_In_iPhoneTriploid(18));
        }];
        label4.text = @"原文：混沌创业营新一期开始招生，想上得可以来找我推荐在这里交到很多良师益友，是幸福也是一辈子得财富。";
        label4.backgroundColor = [UIColor colorWithHexString:@"#F8F8F8"];
        label4.newEdgeInsets = UIEdgeInsetsMake(kHeightProportion_In_iPhoneTriploid(10), kWidthProportion_In_iPhoneTriploid(12), kHeightProportion_In_iPhoneTriploid(10), kWidthProportion_In_iPhoneTriploid(8));
        label4.lineBreakMode = NSLineBreakByTruncatingTail;
        arLabel = label4;
        
        self.selectionStyle = UITableViewCellSelectionStyleBlue;
        UIView *seleView = [[UIView alloc] init];
        seleView.backgroundColor = [UIColor clearColor];
        self.selectedBackgroundView = seleView;
        self.multipleSelectionBackgroundView = seleView;
    }
    return self;
}

- (void)setUIWithStr:(NSString *)str
{
    detailLab.text = str;
}

- (void)setSelectedBackgroundView:(UIView *)selectedBackgroundView
{
    selectedBackgroundView.backgroundColor = [UIColor clearColor];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    if (!self.editing) {
        return;
    }
    [super setSelected:selected animated:animated];
    
    if (self.editing) {
        arLabel.backgroundColor = [UIColor colorWithHexString:@"#F8F8F8"];
    }
    self.tintColor = [UIColor colorWithHexString:@"#A89A60"];
}

- (void)setEditing:(BOOL)editing animated:(BOOL)animated{
    [super setEditing:editing animated:animated];
    if (editing) {
        [self customMultipleChioce];
    } else {
        [self customMultiple];
    }
}

- (void)customMultipleChioce{
    moveNum = kWidthProportion_In_iPhoneTriploid(40);
    [self updateMasonry];
    [UIView animateWithDuration:0.3 animations:^{
        [self layoutIfNeeded];
    }];
}
- (void)customMultiple
{
    moveNum = 0;
    [self updateMasonry];
    [UIView animateWithDuration:0.3 animations:^{
        [self layoutIfNeeded];
    }];
}
- (void)updateMasonry
{
    [likeBtn mas_updateConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(@(-kWidthProportion_In_iPhoneTriploid(15) + self->moveNum));
    }];
    [detailLab mas_updateConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(@(-kWidthProportion_In_iPhoneTriploid(15) + self->moveNum));

    }];
    [arLabel mas_updateConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(@(-kWidthProportion_In_iPhoneTriploid(15) + self->moveNum));
    }];
}

@end
